package com.zerro.litez.compiler.processor.file_builder;

import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;
import com.zerro.litez.compiler.processor.parser.AbstractClassParser;

import javax.annotation.processing.Filer;
import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;
import java.io.IOException;

public abstract class FileBuilder<P extends AbstractClassParser> {

    P parser;

    Element e;


    TypeSpec.Builder classBuilder;

    static Filer filer = null;

    final String packageName = "com.zerro.litez_orm.on_track";
    String runtimePackage = "com.zerro.litez.runtime";

    public FileBuilder(P parser, String name, Element e) {
        this.parser = parser;
        this.e = e;

        classBuilder = TypeSpec.classBuilder(name)
                .addModifiers(Modifier.PUBLIC);


    }

    public static void setFiler(Filer filer) {
        FileBuilder.filer = filer;
    }

    public TypeSpec.Builder getClassBuilder() {
        return classBuilder;
    }

    protected abstract void onBuilding();

    protected void finish() {
        JavaFile file = JavaFile.builder(packageName, classBuilder.build())
         /* 缩进 */   .indent("\t").build();

        try {
            file.writeTo(filer);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
